{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 常量\n", "\n", "## numpy.nan\n", "\n", "- 表示空值。\n", "\n", "```\n", "nan = NaN = NAN\n", "```\n", "\n", "\n", "【例】两个`numpy.nan`是不相等的。\n", "\n", "```python\n", "import numpy as np\n", "\n", "print(np.nan == np.nan) # False\n", "print(np.nan != np.nan) # True\n", "```\n", "\n", "- `numpy.isnan(x, *args, **kwargs)` Test element-wise for NaN and return result as a boolean array.\n", "\n", "【例】\n", "```python\n", "import numpy as np\n", "\n", "x = np.array([1, 1, 8, np.nan, 10])\n", "print(x)\n", "# [ 1. 1. 8. nan 10.]\n", "\n", "y = np.isnan(x)\n", "print(y)\n", "# [False False False True False]\n", "\n", "z = np.count_nonzero(y)\n", "print(z) # 1\n", "```\n", "\n", "\n", "\n", "## numpy.inf\n", "- 表示正无穷大。\n", "\n", "```\n", "Inf = inf = infty = Infinity = PINF\n", "```\n", "\n", "【例】\n", "```python\n", "\n", "```\n", "\n", "## numpy.pi\n", "\n", "- 表示圆周率\n", "\n", "```python\n", "pi = 3.1415926535897932384626433...\n", "```\n", "\n", "## numpy.e\n", "\n", "- 表示自然常数\n", "\n", "```python\n", "e = 2.71828182845904523536028747135266249775724709369995...\n", "```\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.3" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": true }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }